package com.huaboot.generator.service;

import cn.hutool.core.util.StrUtil;;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huaboot.generator.entity.FieldTypeEntity;
import com.huaboot.generator.mapper.FieldTypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;


/**
 * 字段类型管理
 */
@Service
public class FieldTypeServiceImpl  implements FieldTypeService {

    @Autowired
    private FieldTypeMapper fieldTypeMapper;


    @Override
    public Map<String, FieldTypeEntity> getMap() {
        List<FieldTypeEntity> list = fieldTypeMapper.selectList(null);
        Map<String, FieldTypeEntity> map = new LinkedHashMap<>(list.size());
        for (FieldTypeEntity entity : list) {
            map.put(entity.getColumnType().toLowerCase(), entity);
        }
        return map;
    }

    @Override
    public Set<String> getPackageByTableId(Long tableId) {
        Set<String> importList = fieldTypeMapper.getPackageByTableId(tableId);

        return importList.stream().filter(StrUtil::isNotBlank).collect(Collectors.toSet());
    }


}
